<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">
  var initDistributeOptions;
  $(function(){
    var ids= getDataGridChecked("/roleController/selectRoleUsers.html", $('#roleIdFrom').text());
    var initOptions = {
      singleSelect:false,
      frozenColumns: [[
        {
          field: 'id',
          hideColumn:true
        },
        {
        field: 'ck',
        title: '编号',
        width: 150,
        checkbox: true
      }, {
        field: 'userNo',
        title: '员工编号',
        width: 80
      }, {
        field: 'userName',
        title: '账号',
        width: 80
      }, {
        field: 'trueName',
        title: '员工姓名',
        width: 80
      }]],
      columns: [[{
        field: 'dept',
        title: '所属部门',
        width: 150
      }, {
        field: 'position',
        title: '职务',
        width: 150
      }
      ]],
      onLoadSuccess:function(row){//当表格成功加载时执行
        var rowData = row.rows;
        $.each(rowData,function(idx,val){//遍历JSON
          $.each(ids, function(index){
            if(ids[index] == val.id){
              $('#dataGridUser').datagrid("selectRow", idx);
            }
          });
        });
      }
    }
     initAjaxDataGrid("/sysUserController/selectUser.html", $('#dataGridUser'), initOptions);
    $('#distributionFunction').click(function () {
      var nodesObj = $('#dataGridUser').datagrid('getChecked');
      var idArray = new Array();
      $.each(nodesObj,function(index, node){
        idArray.push(node.id +"");
      });
      var postData = {
        roleId:$('#roleIdFrom').text(),
      userIds:idArray
      }
        $.ajax({
          url: "${pageContext.request.contextPath}/roleController/addRoleUsers.html",
          type: "post",
          dataType: "json",
          data: postData,
          success: function (result) {
            parent.$.messager.progress('close');
            if (result && isSuccess(result.result)) {
              parent.$.modalDialog.handler.dialog('close');
            }else{
              parent.$.messager.alert('提示', result.result + " " + result.message, 'info');
            }
            return false;
          },
          error: function (result) {
//			internalError();
            templateInternalError(result.responseText);
            parent.$.messager.progress('close');
            return false;
          }
        });
    });
  })
</script>
<var id="roleIdFrom" style="display: none">${roleId}</var>
<div class="easyui-layout" data-options="fit:true,border:false">
  <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
    <table id="dataGridUser"></table>
    </div>
  </div>
</div>
